
	<script>
		$(function(){
			$('#posterhome').treegrid({
				title:'广告管理',
				iconCls:'icon-save',
                fit:true,
				nowrap: false,
				rownumbers: true,
				animate:true,
				collapsible:true,
				url:'backend.php?r=posterhome/list',
				idField:'code',
				treeField:'Title',
				columns:[[
	                {field:'Title',title:'标题',width:150,align: 'center'},
					{field:'SortOrder',title:'排名',width:150,rowspan:2,align: 'center'},
					{field:'Show',title:'是否显示',width:70,rowspan:2,align: 'center',formatter:formshow},
                    {field:'AddTime',title:'添加时间',width:150,rowspan:2,align: 'center',formatter:formtime},
                    {field:'ClickNum',title:'点击次数',width:150,rowspan:2,align: 'center'},
                    {field:'Own',title:'拥有人',width:150,rowspan:2,align: 'center'},
                    {field:'Relation',title:'联系方式',width:150,rowspan:2,align: 'center'},
                    {field:'AdminPath',title:'后台缩略图',width:150,rowspan:2,align: 'center',formatter:formatProgress}
				]],
                 toolbar:'#tb'
			});
            $('#clickaddposter').bind({
                click:function(){
                    $('#posteradd').dialog({
                        title:'添加广告位',
                        modal:true,
                        minimizable:false,
                        maximizable:false,
                        collapsible:false,
                        width:450,
                        height:280,
                        buttons:[
                        {
                            iconCls:'icon-save',
                            text:'添加',
                            handler:function() {
                                var url = 'backend.php?r=posterhome/PosterAdd';
                                $('#posteraddForm').form('submit',{
                                    url:url,
                                    success:function(data) {
                                        var data = eval('('+data+')');
                                        if (data.success)
                                        {
                                            $.messager.alert('系统提示','操作成功','info');
                                            $('#posteradd').dialog('close');
                                             $('#posterhome').treegrid('reload');
                                        }
                                        else
                                        {
                                            $.messager.alert('系统提示',data.msg,'error');
                                        }
                                    }
                                });
                            }
                    }]
                })
		    }
        });
        $('#clickaddgroup').bind({
            click:function(){
                $('#groupadd').dialog({
                    title:'添加广告组',
                    modal:true,
                    minimizable:false,
                    maximizable:false,
                    collapsible:false,
                    width:450,
                    height:150,
                    buttons:[
                    {
                        iconCls:'icon-save',
                        text:'添加',
                        handler:function() {
                            var url = 'backend.php?r=posterhome/PosterAdd';
                            $('#postergroup').form('submit',{
                                url:url,
                                success:function(data) {
                                    var data = eval('('+data+')');
                                    if (data.success)
                                    {
                                        $.messager.alert('系统提示','操作成功','info');
                                        $('#groupadd').dialog('close');
                                         $('#posterhome').treegrid('reload');
                                    }
                                    else
                                    {
                                        $.messager.alert('系统提示',data.msg,'error');
                                    }
                                }
                            });
                        }
                }]
                })
            }

        })
        $('#refresh').bind({
            click:function(){
                $('#posterhome').treegrid('reload');
            }
        })
        $('#poster_edit').bind({
            click:function(){
                 var selected = $('#posterhome').datagrid('getSelected');
                 if (selected == null) {
                        $.messager.alert('系统提示','请选择数据','warning');
                        return;
                     }
                 if (selected.ParentID == 0) {
                    $('#edit_group').dialog({
                        title:'修改广告组',
                        modal:true,
                        minimizable:false,
                        maximizable:false,
                        collapsible:false,
                        width:450,
                        height:150,
                        buttons:[
                        {
                            iconCls:'icon-save',
                            text:'保存',
                            handler:function() {
                                var url = 'backend.php?r=posterhome/PosterEdit';
                                $('#edit_group_form').form('submit',{
                                    url:url,
                                    success:function(data) {
                                        var data = eval('('+data+')');
                                        if (data.success)
                                        {
                                            $.messager.alert('系统提示','操作成功','info');
                                            $('#edit_group').dialog('close');
                                            $('#posterhome').treegrid('reload');
                                        }
                                        else
                                        {
                                            $.messager.alert('系统提示',data.msg,'error');
                                        }
                                    }
                                });
                            }
                        }]
                    })
                    $('#edit_group_form').form('load',selected);
                }else{
                        $('#edit_poster').dialog({
                            title:'修改广告位',
                            modal:true,
                            minimizable:false,
                            maximizable:false,
                            collapsible:false,
                            width:450,
                            height:280,
                            buttons:[
                            {
                                iconCls:'icon-save',
                                text:'保存',
                                handler:function() {
                                    var url = 'backend.php?r=posterHome/posterEdit';
                                    $('#edit_poster_form').form('submit',{
                                        url:url,
                                        success:function(data) {
                                            var data = eval('('+data+')');
                                            if (data.success)
                                            {
                                                $.messager.alert('系统提示','操作成功','info');
                                                $('#edit_poster').dialog('close');
                                                $('#posterhome').treegrid('reload');
                                            }
                                            else
                                            {
                                                $.messager.alert('系统提示',data.msg,'error');
                                            }
                                        }
                                    });
                                }
                            }]
                        })
                        $('#edit_poster_form').form('load',selected);
                    }
            }
        })
            $('#poster_del').bind({
                click:function(){
                     var selected = $('#posterhome').datagrid('getSelected');
                     if (selected == null) {
                        $.messager.alert('系统提示','请选择数据','warning');
                        return;
                     }
                    $.messager.confirm('确认提示','确认删除么？',function(meg){
                            if (meg) {
                               $.ajax(
                                {
                                   url:'backend.php?r=posterhome/PosterDel',
                                   data: 'id='+selected.ID+'&ParentID='+selected.ParentID,
                                   success:function(data){
                                        var data = eval('('+data+')');
                                            if (data.success)
                                            {
                                                $.messager.alert('系统提示','操作成功','info');
                                                $('#posterhome').treegrid('reload');
                                            }
                                            else
                                            {
                                                $.messager.alert('系统提示',data.msg,'error');
                                            }
                                   }
                                })
                            }
                    });
                }
                }
        )
     })
		function cleardata(formname){
			$('#'+formname).form('clear');
		}
        function formatProgress(value) {
            if(value){
                var s = '<img src="'+value+'">';
                return s;
            }
        }
        function formtime(value) {
            var timeall=new Date(value*1000);
            times=timeall.getFullYear()+"-"+(timeall.getMonth()+1)+"-"+timeall.getDate();
            return times;
        }
        function formshow(value) {
            if(value == 0){
                return '否';
            }else{
                return '是';
            }
        }
	</script>


	<table id="posterhome"></table>

    <div id="tb">
<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-reload',plain:true" id='refresh'>刷新</a>
<a href="javascript:void(0)" id="mb1" class="easyui-menubutton" data-options="menu:'#mm1',iconCls:'icon-add'">添加</a>
<a href="#" class="easyui-linkbutton" id='poster_edit' data-options="iconCls:'icon-edit',plain:true">编辑</a>
<a href="#" class="easyui-linkbutton" id='poster_del' data-options="iconCls:'icon-remove',plain:true">删除</a>
   	<div id="mm1" style="width:100px;">
		<div id='clickaddposter'>添加广告位</div>
		<div id='clickaddgroup'>添加广告组</div>
	</div>
</div>



    <div id='posteradd'>
        <center>
    <form id="posteraddForm" method="post"    enctype="multipart/form-data">
	           <br>标题:
	             　　<input class="easyui-validatebox" type="text" id="Title" data-options="required:true" validType="length[1,32]"  invalidMessage="标题长度在1-32位之间" missingMessage="请输入标题" name='Title' ></input>
                <br>
              广告分类:　　　　　<select  name='ParentID'>
                <?php foreach($arr as $v){ ?>
                <option value='<?php echo $v['ID'] ?>'><?php echo $v['Title'] ?></option>
                <?php } ?>
                </select>
	            <br>排名:
	             　　<input class="easyui-numberbox" id="SortOrder" type="text"  value='50' data-options="required:true" validType="length[1,11]" invalidMessage="排名长度在1-11位之间" missingMessage="请输入排名" name='SortOrder'></input>

	  <br> 是否显示:　显示<input   type="radio"  value='1'  checked name='Show'>　　不显示<input type='radio' value='0' name='Show'>
      <br>链接地址: <input type='text' class="easyui-validatebox" name='Src' data-options="required:true" missingMessage='请输入URL' validType='url' invalidMessage='请输入URL地址' >
                <br>拥有人: 　<input type='text' class="easyui-validatebox" name='Own' data-options="required:true" missingMessage="请输入拥有人" validType="length[1,32]" invalidMessage="拥有人在1-32位之间">
                <br>联系方式: <input type='text' class="easyui-validatebox" name='Relation' data-options="required:true" missingMessage="请输入联系方式" validType="length[1,64]" invalidMessage="联系方式在1-64位之间">
                <input type='hidden' value='poster' name='type'>
                <br>　　　　　上传图片: <input type='file' name='filename'>
	    </form>
                <center>
    </div>
     <div id='groupadd'  style="padding:20px;">
        <center>
    <form id="postergroup" method="post"    enctype="multipart/form-data">组名:
	             　　<input class="easyui-validatebox" type="text" id="Title" data-options="required:true" validType="length[1,32]"  invalidMessage="组名长度在1-32位之间" missingMessage="请输入组名" name='Title' ></input>
	            <br>排名:
	             　　<input class="easyui-numberbox" id="SortOrder" type="text"  value='50' data-options="required:true" validType="length[1,11]" invalidMessage="排名长度在1-11位之间" missingMessage="请输入排名" name='SortOrder'></input>
                 <input type='hidden' value='group' name='type'>
	    </form>
                <center>
        </div>
             <div id='edit_group'  style="padding:20px;">
        <center>
    <form id="edit_group_form" method="post"    enctype="multipart/form-data">组名:
	             　　<input class="easyui-validatebox" type="text" id="edit_Title" data-options="required:true" validType="length[1,32]"  invalidMessage="组名长度在1-32位之间" missingMessage="请输入组名" name='Title' ></input>
	            <br>排名:
	             　　<input class="easyui-numberbox" id="edit_SortOrder" type="text"   value='50' data-options="required:true" validType="length[1,11]" invalidMessage="排名长度在1-11位之间" missingMessage="请输入排名" name='SortOrder'></input>
                 <input type='hidden' value='group' name='type'>
                 <input type='hidden' id='edit_ID' name='ID'>
	    </form>
                <center>
        </div>


        <div id='edit_poster'>
        <center>
    <form id="edit_poster_form" method="post"    enctype="multipart/form-data">
	           <br>标题:
	             　　<input class="easyui-validatebox" type="text" id="edit_poster_Title" data-options="required:true" validType="length[1,32]"  invalidMessage="标题长度在1-32位之间" missingMessage="请输入标题" name='Title' ></input>
                <br>
              广告分类:　　　　　<select  id='edit_poster_ParentID' name='ParentID'>
                <?php foreach($arr as $v){ ?>
                <option value='<?php echo $v['ID'] ?>'><?php echo $v['Title'] ?></option>
                <?php } ?>
                </select>
	            <br>排名:
	             　　<input class="easyui-numberbox" id="edit_poster_SortOrder" type="text"   data-options="required:true" validType="length[1,11]" invalidMessage="排名长度在1-11位之间" missingMessage="请输入排名" name='SortOrder'></input>

	  <br> 是否显示:　显示<input   type="radio"  value='1'  id='edit_Show1' checked name='Show'>　　不显示<input id='edit_Show0' type='radio' value='0' name='Show'>
      <br>链接地址: <input type='text' class="easyui-validatebox" id='edit_poster_Src' name='Src' data-options="required:true" missingMessage='请输入URL' validType='url' invalidMessage='请输入URL地址' >
                <br>拥有人: 　<input type='text' class="easyui-validatebox" id='edit_poster_Own' name='Own' data-options="required:true" missingMessage="请输入拥有人" validType="length[1,32]" invalidMessage="拥有人在1-32位之间">
                <br>联系方式: <input type='text' class="easyui-validatebox" id='edit_poster_Relation' name='Relation' data-options="required:true" missingMessage="请输入联系方式" validType="length[1,64]" invalidMessage="联系方式在1-64位之间">
                <input type='hidden' value='poster' name='type'>
                <input type='hidden' id='edit_poster_ID' name='ID'>
                <br>
	    </form>
                <center>
    </div>





